package jrain.fw.dao.common.parser.bean;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import jrain.fw.core.dao.bean.SqlBean;

public class RootExpression extends SqlExpression {

	private List<SqlExpression> chilrens = new ArrayList<SqlExpression>();

	public void addExpression(SqlExpression expression) {
		chilrens.add(expression);
	}

	public List<SqlExpression> getChilrens() {
		return chilrens;
	}

	public String calcExpression() {
		StringBuilder sb = new StringBuilder();
		for (SqlExpression expression : chilrens) {
			sb.append(expression.calcExpression());
		}
		return sb.toString();
	}

	public SqlBean calcSql(Map<String, Object> sqlCfg, Map<String, Object> paramData,Map<String,Object> ctx) {
		SqlBean sqlInfo = new SqlBean();
		for (SqlExpression expression : chilrens) {
			SqlBean temp =  expression.calcSql(sqlCfg, paramData,ctx);
			sqlInfo.append(temp.getSql().toString());
			List<Object> list = temp.getParams();
			for (Object object : list) {
				sqlInfo.addParam(object);
			}
		}
		return sqlInfo;
	}

}
